<?php
abstract class Config extends Object
{
    public $DIR;
    public $DIR_CONFIG;
    public $DIR_LIBS;
    public $DIR_MODELS;
    public $DIR_CONTROLS;
    public $DIR_CONTROLLERS;
    public $DIR_MODULES;
    public $DIR_TESTS;
    public $DIR_TMP;
    public $DIR_LOGS;
    public $DIR_CACHE;
    public $DIR_CACHE_DATA;
    public $DIR_GEN;
    public $DIR_DOCS;
    public $DIR_DATA;
    public $DIR_TEMPLATES;
    public $DIR_CURRENT_TEMPLATE;
    public $DIR_HTML_CONTROLLERS;
    public $DIR_HTML_CONTROLS;
    public $DIR_SHARED_JS;
    public $DIR_CSS;
    public $DIR_IMG;
    public $DIR_JS;
    public $DIR_CONTENT;
    public $DIR_PHOTO;

    public $HOST;
    public $HTTP_HOST;
    public $HTTPS_HOST;

    public $URL;
    public $URL_APP;
    public $URL_SHARED_JS;
    public $URL_MODULES;
    public $URL_IMG;
    public $URL_JS;
    public $URL_CSS;
    public $URL_CACHE;
    public $URL_DEFAULT;
    public $URL_UNAUTHORIZED;
    public $URL_CONTENT;
    public $URL_PHOTO;

    protected $URL_TEMPLATES;
    protected $URL_CURRENT_TEMPLATE;
    protected $URL_TMP;

    public $FILE_CACHE_USING;
    public $USING_DIRS;

    public $DEFAULT_TEMPLATE = 'default';
    public $CURRENT_TEMPLATE;

    public $VERSION;

    public function Config($url = null)
    {
        parent::__construct();
        $reflection = new ReflectionClass($this);
        $this->DIR = dirname($reflection->getFileName());
        $this->DIR_CONFIG       = $this->DIR.DS.'config';
        $this->DIR_LIBS         = $this->DIR.DS.'libs';
        $this->DIR_MODELS       = $this->DIR.DS.'models';
        $this->DIR_CONTROLS     = $this->DIR.DS.'controls';
        $this->DIR_CONTROLLERS  = $this->DIR.DS.'controllers';
        $this->DIR_MODULES      = $this->DIR.DS.'modules';
        $this->DIR_TESTS        = $this->DIR.DS.'tests';
        $this->DIR_TMP          = $this->DIR.DS.'tmp';
        $this->DIR_LOGS         = $this->DIR_TMP.DS.'logs';
        $this->DIR_CACHE        = $this->DIR_TMP.DS.'cache';
        $this->DIR_CACHE_DATA   = $this->DIR_CACHE.DS.'data';
        $this->DIR_GEN          = $this->DIR_TMP.DS.'gen';
        $this->DIR_DOCS         = $this->DIR.DS.'docs';
        $this->DIR_DATA         = $this->DIR.DS.'data';
        $this->DIR_SHARED_JS    = $this->DIR.DS.'js';
        $this->DIR_TEMPLATES    = $this->DIR.DS.'templates';
        $this->DIR_CONTENT      = $this->DIR.DS.'content';
        $this->DIR_PHOTO        = $this->DIR_CONTENT.DS.'photo';

        $this->FILE_CACHE_USING = $this->DIR_CACHE_DATA.DS.'using.php';

        $this->USING_DIRS = array(
            $this->DIR_MODELS,
            $this->DIR_CONTROLLERS,
            $this->DIR_LIBS,
            $this->DIR_CONTROLS,
            $this->DIR_MODULES,
        );

        $this->HOST = $_SERVER['HTTP_HOST'];

        $this->HTTP_HOST = 'http://'.$this->HOST;
        $this->HTTPS_HOST = 'https://'.$this->HOST;

        $this->URL              = is_null($url) ? URL_ROOT : $url.FS.basename($this->DIR);
        $url                    = is_null($url) ? $this->URL.FS.'app' : $this->URL;
        $this->URL_SHARED_JS    = $url.FS.basename($this->DIR_SHARED_JS);
        $this->URL_MODULES      = $url.FS.basename($this->DIR_MODULES);
        $this->URL_TEMPLATES    = $url.FS.basename($this->DIR_TEMPLATES);
        $this->URL_TMP          = $url.FS.basename($this->DIR_TMP);
        $this->URL_CACHE        = $this->URL_TMP.FS.basename($this->DIR_CACHE);
        $this->URL_CONTENT      = $url.FS.basename($this->DIR_CONTENT);
        $this->URL_PHOTO        = $this->URL_CONTENT.FS.basename($this->DIR_PHOTO);

        $this->URL_DEFAULT      = URL_ROOT.FS.basename($this->DIR);
        $this->URL_UNAUTHORIZED = URL_ROOT.FS.'unauthorized';

        $this->SetTemplate();
    }

    public function AddSharedJsNoPack($files)
    {
        Layout::AddJsFileNoPack($files, $this, 'SHARED_JS');
    }

    public function AddJsNoPack($files)
    {
        Layout::AddJsFileNoPack($files, $this, 'JS');
    }

    public function AddSharedJs($files)
    {
        Layout::AddFile($files, $this, 'SHARED_JS');
    }

    public function AddJs($files)
    {
        Layout::AddFile($files, $this, 'JS');
    }

    public function AddCss($files)
    {
        Layout::AddFile($files, $this, 'CSS');
    }

    public function GetCurrencyModel()
    {
        return CmsCurrencyModel::GetInstance();
    }

    public function GetUserModel()
    {}

    public function SetTemplate($template = null)
    {
        $template = trim($template);
        $this->CURRENT_TEMPLATE     = $template ? $template : $this->DEFAULT_TEMPLATE;
        $this->DIR_CURRENT_TEMPLATE = $this->DIR_TEMPLATES.DS.$this->CURRENT_TEMPLATE;
        $this->DIR_HTML_CONTROLLERS = $this->DIR_CURRENT_TEMPLATE.DS.'controllers';
        $this->DIR_HTML_CONTROLS    = $this->DIR_CURRENT_TEMPLATE.DS.'controls';
        $this->DIR_HTML_ELEMENTS    = $this->DIR_CURRENT_TEMPLATE.DS.'elements';
        $this->DIR_CSS              = $this->DIR_CURRENT_TEMPLATE.DS.'css';
        $this->DIR_IMG              = $this->DIR_CURRENT_TEMPLATE.DS.'img';
        $this->DIR_JS               = $this->DIR_CURRENT_TEMPLATE.DS.'js';

        $this->URL_CURRENT_TEMPLATE = $this->URL_TEMPLATES.FS.$this->CURRENT_TEMPLATE;
        $this->URL_IMG              = $this->URL_CURRENT_TEMPLATE.FS.basename($this->DIR_IMG);
        $this->URL_JS               = $this->URL_CURRENT_TEMPLATE.FS.basename($this->DIR_JS);
        $this->URL_CSS              = $this->URL_CURRENT_TEMPLATE.FS.basename($this->DIR_CSS);
    }
}
?>
